<?php

use think\migration\db\Column;
use think\migration\Migrator;

class ExtensionRefund extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $this->table('extension_refund')
            ->setComment('支付退款记录表')
            ->addColumn(Column::integer('payment_id')->setComment('关联支付记录ID'))
            ->addColumn(Column::char('order_sn', 20)->setComment('支付订单编号'))
            ->addColumn(Column::char('out_refund_no', 20)->setComment('商户退款单号'))
            ->addColumn(Column::string('reason'))->setComment('退款原因')
            ->addColumn(Column::decimal('amount', 10, 2)->setComment('退款金额（元）'))
            ->addColumn(Column::tinyInteger('status')->setComment('退款状态：0-待退款/1-退款中/2-成功/3-失败'))
            ->addColumn(Column::char('refund_id', 32)->setComment('三方退款唯一订单号'))
            ->addColumn(Column::integer('success_time')->setComment('退款成功时间'))
            ->addColumn(Column::json('refund_param')->setComment('退款参数'))
            ->addColumn(Column::json('refund_result')->setComment('查询退款结果信息'))
            ->addColumn(Column::string('status_desc')->setComment('退款状态说明'))
            ->addTimestamps()
            ->addIndex(['refund_id'])
            ->addIndex(['out_refund_no'], ['unique' => true])
            ->addIndex(['order_sn'])
            ->create();
    }
}
